<?php
include '../common.php';

$rule = [
	'name'      => ['kong','用户名不能为空'],
	'password'  => ['kong','密码不能为空'],
	'password1' => ['kong','确定密码不能为空'],
	'email'     => ['kong','邮箱不能为空'],
	'phone'     => ['kong','电话不能为空'],
	'email'     => ['is_email','邮箱不正确'],
	'phone'     => ['is_phone','电话不正确'],
];
$a = panduan($rule);
if($a['code'] == 0){
	exit($a['msg']);
}

$name      = trim($_POST['name']);
$password  = trim($_POST['password']);
$password1 = trim($_POST['password1']);
$email     = trim($_POST['email']);
$phone     = trim($_POST['phone']);
$user      = trim((int)$_POST['user']);

if ($password !== $password1) {
	exit('两次密码不一致');
}
$password = md5($password);

$sql  = "SELECT * FROM user where name = '$name'";
$row = select($sql,$DB);
if ($row) {
	exit('用户名存在');
}
$time = time();
$sql  = "INSERT INTO user (name,password,email,phone,user,hour) VALUES ('$name', '$password', '$email','$phone','$user','$time')";
$row = insert($sql,$DB);
if (!$row ) {
	exit('增加失败');
}
header("location:../admin_user/user.php",302);